package com.huhu.objects;

import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.text.Text;
import org.andengine.extension.physics.box2d.PhysicsFactory;
import org.andengine.extension.physics.box2d.PhysicsWorld;
import org.andengine.opengl.vbo.VertexBufferObjectManager;

import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.huhu.manager.ResourcesManager;

public class TextSprite extends Sprite{
	private FixtureDef fixtureDef;
	private Body body;
	private PhysicsWorld physicsWorld;
	private String text;
	private Player player;

	public TextSprite(float px, float py, String text, VertexBufferObjectManager vbom, PhysicsWorld physicsWorld, Player player){
		super(px, py, 64, 64, ResourcesManager.getInstance().unknow_brickover_region, vbom);
		
		this.physicsWorld = physicsWorld;
		this.text = text;
		this.player = player;
		
		final Text textShow = new Text(0, 0, ResourcesManager.getInstance().font, (CharSequence) text, vbom);
		textShow.setPosition(32-textShow.getWidth()/2, 32-textShow.getHeight()/2);
		attachChild(textShow);
		
		createBody();
	}
	
	private void createBody(){
		fixtureDef = PhysicsFactory.createFixtureDef(0, 0.01f, 0.5f);
		body = PhysicsFactory.createBoxBody(physicsWorld, this, BodyType.StaticBody, fixtureDef);
		body.setUserData(text);
		body.setActive(false);
	}
	
	public void setBodyActive(boolean active){
		body.setActive(active);
	}
	
	public boolean getBodyActive(){
		return body.isActive();
	}
}
